package middleware

import (
	"github.com/gin-gonic/gin"
	"project_api/intrenal/api/response"
	"project_api/pkg"
)

func MiddleWare() gin.HandlerFunc {
	return func(c *gin.Context) {
		header := c.GetHeader("token")
		if header == "" {
			response.Response(c, 400, "暂未登录", nil)
			c.Abort()
			return
		}
		token, s := pkg.GetToken(header)
		if s != "" {
			response.Response(c, 400, s, nil)
			c.Abort()
			return
		}
		s2 := token["user"].(string)
		c.Set("userId", s2)
		c.Next()
	}
}
